package com.tian.controller;

import com.tian.entity.UserAdmin;
import com.tian.entity.UserApplyApproveLog;
import com.tian.service.UserApplyApproveLogService;
import com.tian.util.ResultObj;
import com.tian.util.WebUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年09月18日 21:04
 * 在线刷题 1200+题和1000+篇干货文章：<a href="https://woaijava.cc/">博客地址</a>
 * <p>
 * 审批记录
 */
@Controller
@RequestMapping("/user/apply")
public class UserApplyApproveLogController {

    @Resource
    private UserApplyApproveLogService userApplyApproveLogService;

    /**
     * 审批用户额度审批 记录
     */
    @PostMapping("/approve")
    public ResultObj approve(@RequestBody UserApplyApproveLog userApplyApproveLog) {
        Object session = WebUtils.getSession().getAttribute("user");
        if (session == null) {
            return ResultObj.LOGIN_ERROR_PASS;
        }
        UserAdmin userAdmin = (UserAdmin) session;
        userApplyApproveLog.setApprovorId(userAdmin.getId());
        userApplyApproveLog.setCreateTime(new Date());
        userApplyApproveLogService.add(userApplyApproveLog);
        return ResultObj.ADD_SUCCESS;
    }
}
